package com.example.order.converter;

import com.example.common.Interface.order.entity.vo.OrderVO;
import com.example.common.Interface.user.entity.vo.AddressVO;
import com.example.order.dao.po.Order;
import com.example.order.enums.PaymentStatus;

public class OrderConverter {
    public static OrderVO toOrderVO(Order order){
        return OrderVO.builder()
                .orderId(String.valueOf(order.getId()))
                .userId(order.getUserId())
                .userCurrency(order.getUserCurrency())
                .address(AddressVO.deserialize(order.getAddress())) // 假设地址简单转换
                .email(order.getEmail())
                .createdAt(order.getCreatedAt())
                .build();

    }

    public static Order toOrder(OrderVO orderVO){
        return Order.builder()
                .id(Long.parseLong(orderVO.getOrderId()))
                .userId(orderVO.getUserId())
                .userCurrency(orderVO.getUserCurrency())
                .address(orderVO.getAddress().serialize())
                .email(orderVO.getEmail())
                .createdAt(orderVO.getCreatedAt())
                .paymentStatus(PaymentStatus.PENDING)
                .cost(0L)
                .deleted(false)
                .build();
    }
}
